package com.djk.daily.kafka.producer;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;

/**
 * @Description 分配Partition的配置
 * @Author dujunkai
 * @Date 2021/12/3 3:09 下午
 **/
public class SimplePartition implements Partitioner {
    @Override
    public int partition(String topic, Object key, byte[] bytes, Object o1, byte[] bytes1, Cluster cluster) {
        //key的形式key-1,key-2,key-3
        Integer serial = Integer.valueOf(key.toString().split("-")[1]);
        System.out.println("key = " + key);
        return serial % 2;
    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> map) {

    }
}
